<?php
/**
 * @copyright  Copyright  LexisNexis, a division of Reed Elsevier Inc. All rights reserved.
 */
namespace App\Console\Commands\AnalysisScripts;
use Elasticsearch\Client;

abstract class AnalysisBase {
    private $esClient;
    private $esDefault = [];

    public function __construct(Client $esClient) {
        $this->esClient = $esClient;
        $this->esDefault = [
            'index' => env('ES_INDEX'),
            'type'  => env('ES_TYPE'),
        ];
    }

    protected function search(array $body, array $options = array()) {
        $params = [
            'body'  => $body
        ];
        $condition = $this->esDefault + $params + $options;
        $response = $this->esClient->search($condition);
        return $response;
    }

    protected function count(array $body, array $options = array()) {
        $params = [
            'body'  => $body
        ];
        $condition = $this->esDefault + $params + $options;
        $response = $this->esClient->count($condition);

        return !empty($response['count']) ? (int) $response['count'] : 0;
    }
}